//
//  CZBaseTableViewController.swift
//  FYBXinLang
//
//  Created by mac1 on 16/3/20.
//  Copyright © 2016年 mac1. All rights reserved.
//

import UIKit
// MARK: - CZBaseTableViewController 扩展,实现 CZVistorViewDelegate 协议
// 扩展,和oc category类似, estension 可以实现协议, 方便代码统一管理
extension CZBaseTableViewController: CZVistorViewDelegate {
    
    func vistorViewWillRegister() {
        print("CZBaseTableViewController:\(__FUNCTION__)")
    }
    
    func vistorViewWillLogin() {
        print("CZBaseTableViewController:\(__FUNCTION__)")
    }
    
    
}

class CZBaseTableViewController: UITableViewController {

      //用户是否登录标志
    var userLogin = false
    
    //懒加载
    private lazy var vistorView:CZVistorView = CZVistorView()
    
    
    override func loadView() {
        userLogin ? super.loadView() : setupVisitorView()
    }
    
    
    //设置访客视图
    private func setupVisitorView() {
      
//      vistorView = CZVistorView()
        
        view = vistorView
        
        //判断当前是哪个控制器
        
        if self is CZHomeViewController {
          //开始动画 旋转转轮
            vistorView.startRotationAnimation()
        }else if self is CZMessageViewController {
         vistorView.setupVisitorInfo("visitordiscover_image_message", message:  "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is CZDiscoverViewController {
            vistorView.setupVisitorInfo("visitordiscover_image_message", message:  "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is CZProfileViewController {
            vistorView.setupVisitorInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        vistorView.vistorViewDelegate =  self
        
        //添加导航栏按钮
        //左边注册
        navigationItem.leftBarButtonItem = UIBarButtonItem(title:  "注册", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
        //右边登录
        navigationItem.rightBarButtonItem = UIBarButtonItem(title:   "登录", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

 
    
    
    

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }

    /*
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)

        // Configure the cell...

        return cell
    }
    */

    /*
    // Override to support conditional editing of the table view.
    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the specified item to be editable.
        return true
    }
    */

    /*
    // Override to support editing the table view.
    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == .Delete {
            // Delete the row from the data source
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        } else if editingStyle == .Insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }    
    }
    */

    /*
    // Override to support rearranging the table view.
    override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {

    }
    */

    /*
    // Override to support conditional rearranging of the table view.
    override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the item to be re-orderable.
        return true
    }
    */

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
